<template>
    <section>
        <!--工具条-->

        <div class="section-content clearfix">
            <el-col :span="24" style="padding-bottom: 0px;">
                <el-form :inline="true" :model="filters">
                    <el-form-item >
                        <el-input keydown.enter.prevent v-model="filters.name" placeholder="组织名" @keyup.enter.native="getUsers()"></el-input>
                    </el-form-item>
                    <el-form-item >
                            <el-input v-model="filters.phone" placeholder="电话号码" @keyup.enter.native="getUsers()"></el-input>
                    </el-form-item>
    
                    <el-form-item >
                        <el-button :type="buttonColor" v-on:click="getUsers">查询</el-button>
                    </el-form-item>
                     <!-- v-if="menubt.indexOf('/user/add_child_company')>-1" -->
                    <el-form-item>
                        <el-button :type="buttonColor" @click="handleAdd">创建</el-button>
                    </el-form-item>
                </el-form>
            </el-col>

            <!--列表-->
            <el-table :data="users" highlight-current-row v-loading="listLoading" @selection-change="selsChange" :header-row-style="{backgroundColor: titleColor}" style="width: 100%;">
                <!-- <el-table-column type="selection">
                </el-table-column> -->
                <el-table-column align="center" type="index" label="序号"  width="80":index="indexMethod">
                </el-table-column>
                <el-table-column align="center" prop="name" label="组织名">
                    <template scope="scope">
                        <span class="pb-name" @click="details(scope.$index,scope.row)">{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="site" label="网址">
                </el-table-column>
                <el-table-column align="center" prop="phone" label="电话号码">
                </el-table-column>
                
                <el-table-column align="center" prop="statusText" label="当前状态">
                    <!-- <template scope="scope">
                        <span v-if="scope.row.status==1">已停用</span>
                        <span v-if="scope.row.status==2">已启用</span>
                    </template> -->
                </el-table-column>
                <el-table-column align="center" label="状态操作">
                    <template scope="scope">

                        <el-button v-if="scope.row.status==2" size="small" @click="stateput( scope.row)" type="small"
                            plain>停用</el-button>
                        <el-button v-if="scope.row.status==1" size="small" :type="buttonColor" @click="stateput( scope.row)"
                            plain>启用</el-button>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="客户关系">
                    <template scope="scope">
                        <el-button size="small" @click="dendrogram(scope.$index,scope.row)" type="small" plain>树状图</el-button>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="expirationTime" label="过期时间">
                </el-table-column>
                
                <!-- <el-table-column align="center" label="权限">
                    <template scope="scope">

                        <el-button size="small" @click="exentEdit(scope.$index, scope.row)">权限编辑</el-button>
                       
                    </template>
                </el-table-column> -->
                <el-table-column align="center" label="操作">
                    <template scope="scope">
                        <!-- <i @click="companyedit(scope.$index, scope.row)" title="编辑" icon="el-icon-edit" circle class="pb-icon icon-edit"></i> -->
                        <i @click="handleDel(scope.$index, scope.row)" icon="el-icon-delete" circle title="删除" class="pb-icon icon-delete"></i>

                    </template>
                </el-table-column>
            </el-table>

            <!--工具条-->
            <el-col :span="24" class="toolbar">
                <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total"
                    style="float:right;">
                </el-pagination>
            </el-col>
        </div>
        <!--编辑界面-->
        <el-dialog title="编辑" v-show="editFormVisible" :custom-class="dialogTitleColor" @close="editFormVisible = false">
            <div slot="footer" style="text-align: left; ">
                <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
                    <el-form-item label="用户名" prop="userName">
                        <el-input v-model="editForm.userName" auto-complete="off"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="密码">
                            <el-input type="text" v-model="editForm.password" disabled></el-input>
                        </el-form-item> -->
                    <el-form-item label="手机号码" prop="phone">
                        <el-input type="number" v-model="editForm.phone"></el-input>
                    </el-form-item>

                    <el-form-item label="邮箱">
                        <el-input v-model="editForm.email"></el-input>
                    </el-form-item>

                    <!-- <el-form-item label="权限类型">
                            <el-radio-group v-model="editForm.authType">
                                <el-radio label="0">普通</el-radio>
                                <el-radio label="1">厂商</el-radio>
                            </el-radio-group>
                        </el-form-item> -->

                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">

                <el-button :type="buttonColor" @click.native="reset_passwords(editForm.childUserId)" :loading="editLoading">重置密码</el-button>
                <el-button @click.native="editFormVisible = false">取消</el-button>
                <el-button :type="buttonColor" @click.native="editSubmit" :loading="editLoading">提交</el-button>
            </div>
        </el-dialog>
        <el-dialog title="组织信息编辑" v-show="companyVisible" :custom-class="dialogTitleColor" @close="companyVisible = false">
            <div slot="footer" style="text-align: left; ">
                <el-form ref="form" :model="form" label-width="100px" >
                    <el-form-item label="组织名" prop="userName">
                        <el-input v-model="form.name" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="电话号码" prop="phone">
                        <el-input v-model="form.phone" auto-complete="off"></el-input>
                    </el-form-item>
                     <el-form-item label="地址">
                        <div id="editmap" ref="editmap">
                        </div>
                        <div class="map_position clearfix ng-binding">
                            <el-input type="text" id="editId" placeholder="地址" v-model="form.address" class="input_style"></el-input>
                            <!-- <div>{{form.address}}</div> -->
                            经度：{{form.longitude}},纬度：{{form.latitude}}
                        </div>
                    </el-form-item>
                    <el-form-item label="用户绑定权限">
                        
                     <el-col :span="10" style="margin-bottom:10px;">
                                <el-input v-model="auth[3].name"  auto-complete="off" placeholder="拥有者"></el-input>
                            </el-col>
                                 <el-col :span="10" style="margin-bottom:10px;margin-left:10px"> 
                                <el-input v-model="auth[2].name" auto-complete="off" placeholder="管理员"></el-input>
                            </el-col>
                            <el-col :span="10" style="margin-bottom:10px;">
                                <el-input v-model="auth[1].name" auto-complete="off" placeholder="已授权"></el-input>
                            </el-col>
                                <el-col :span="10" style="margin-bottom:10px;margin-left:10px">
                                <el-input v-model="auth[0].name" auto-complete="off" placeholder="待授权"></el-input>
                            </el-col>
                                <el-col :span="10" style="margin-bottom:10px;">
                                <el-input v-model="auth[4].name" auto-complete="off" placeholder="拒绝"></el-input>
                            </el-col>
                         
                    </el-form-item>
                    <el-form-item  label="角色权限">
                        
                            <el-button size="small" @click="exentEdit()">权限菜单</el-button>                                         
                       
                    </el-form-item>
                    <el-form-item label="过期时间">
                     <el-radio v-model="form.expirationStatus" :label="1" @change="second2()">永不过期</el-radio>
                     <el-radio v-model="form.expirationStatus" :label="0">选择日期</el-radio>
                     <el-date-picker v-show="form.expirationStatus == 0" v-model="value1" type="datetime" placeholder="选择日期时间" @change="second1()">
                        </el-date-picker>
                </el-form-item>
                    <el-form-item label="网址">
                        <el-input v-model="form.site" auto-complete="off"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="等级选择">
                        <el-select v-model="form.dataRestrict" placeholder="请选择">
                            <el-option label="公开"  value="0"></el-option>
                            <el-option label="一级"  value="1"></el-option>
                            <el-option label="二级"  value="2"></el-option>
                            <el-option label="三级"  value="3"></el-option>
                            <el-option label="四级"  value="4"></el-option>
                            <el-option label="五级"  value="5"></el-option>
                            <el-option label="六级"  value="6"></el-option>
                            <el-option label="七级"  value="7"></el-option>
                            <el-option label="八级"  value="8"></el-option>
                            <el-option label="九级"  value="9"></el-option>
                            <el-option label="十级"  value="10"></el-option>
                            <el-option label="不公开"  value="11"></el-option>
                        </el-select>
                    </el-form-item> -->
                    <el-form-item label="备注" prop="remark">
                        <el-input type="textarea" v-model="form.remark"></el-input>
                    </el-form-item>
                    <el-form-item label="图片">
                    <el-upload class="avatar-uploader" :headers="fileList" action="/api/auth/image_file/upload"
                        :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                        <img v-if="form.logo" :src="form.logo" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="companyVisible = false">取消</el-button>
                <el-button :type="buttonColor" @click.native="companySubmit" :loading="editLoading">提交</el-button>
            </div>
        </el-dialog>
        <!--权限编辑界面-->
        <el-dialog title="权限编辑" v-show="editexentble" :custom-class="dialogTitleColor" @close="editexentble = false">
            <div slot="footer" style="text-align: left; ">

                <el-transfer v-model="editrole.roleList" :titles="['未选中', '选中']" :data="userlists" style="margin-left:30px;padding-bottom:20px;"></el-transfer>

            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editexentble = false">取消</el-button>
                <el-button :type="buttonColor" @click.native="editSubmitrole" :loading="editLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--新增界面-->
        <el-dialog title="创建" v-show="addFormVisible" :custom-class="dialogTitleColor" @close="addFormVisible = false">
            <div slot="footer" style="text-align: left; ">
                <el-form :model="addForm" label-width="90px" :rules="addFormRules" ref="addForm">
                    <el-form-item label="用户名" v-model="addForm.userName" prop="userName">
                        <el-input v-model="addForm.userName" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="昵称" v-model="addForm.nickName" prop="nickName">
                        <el-input v-model="addForm.nickName" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="password">
                        <el-input type="password" v-model="addForm.password"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码" prop="phone">
                        <el-input type="number" v-model="addForm.phone"></el-input>
                    </el-form-item>
                    <el-form-item label="组织名称" prop="companyName">
                        <el-input v-model="addForm.companyName"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱">
                        <el-input v-model="addForm.email"></el-input>
                    </el-form-item>
                    <el-form-item label="权限选择">
                        <el-select v-model="addForm.roleList" multiple placeholder="请选择">
                            <el-option v-for="item in roleList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="等级选择">
                        <el-select v-model="addForm.dataRestrict" placeholder="请选择">
                            <el-option label="公开"  value="0"></el-option>
                            <el-option label="一级"  value="1"></el-option>
                            <el-option label="二级"  value="2"></el-option>
                            <el-option label="三级"  value="3"></el-option>
                            <el-option label="四级"  value="4"></el-option>
                            <el-option label="五级"  value="5"></el-option>
                            <el-option label="六级"  value="6"></el-option>
                            <el-option label="七级"  value="7"></el-option>
                            <el-option label="八级"  value="8"></el-option>
                            <el-option label="九级"  value="9"></el-option>
                            <el-option label="十级"  value="10"></el-option>
                            <el-option label="不公开"  value="11"></el-option>
                        </el-select>
                    </el-form-item> -->
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click.native="addFormVisible = false">取消</el-button>
                <el-button :type="buttonColor" @click.native="addSubmit" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>
        <el-dialog title="删除" v-show="delVisible" v-model="delVisible" :custom-class="dialogTitleColor" @close="delVisible=false">
            <div slot="footer" style="text-align: left; ">
                <el-form @submit.native.prevent :model="addForm" label-width="100px" :rules="addFormRules"
                    ref="addForm">
                    <el-form-item label="验证码">
                        <el-input v-model="verifyCode" auto-complete="off"></el-input>
                    </el-form-item>


                </el-form>
                <div slot="footer" class="dialog-footer" style="text-align: right;">

                    <el-button type="success" @click.native="codeadd">获取验证码</el-button>
                    <el-button @click.native="delVisible = false">取消</el-button>
                    <el-button :type="buttonColor" @click.native="delclick" :loading="addLoading">提交</el-button>
                </div>
            </div>
        </el-dialog>
    </section>
</template>

<script>
    //import NProgress from 'nprogress'
    import {
        query_user,
        user_query,
        query_userpost,
        query_userput,
        query_userdelete,
        query_userpermission,
        user_add_child,
        user_edit_child,
        user_edit_child_role,
        user_role_query_child_user,
        user_get_childr,
        company_get,
        company_put,
        company_post,
        user_reset_child_pass,
        company_enable,
        company_disable,
        user_delete_child,
        send_auth_pass_code,
        user_add_childcompany,
        user_querycompany,
        user_delete_company
    } from '../../../api/api';

    export default {
        data() {
            const generateDatas = _ => {
                const data = [];
                let para = {
                    pageNo: 1,
                    pageSize: 1000
                };
                //NProgress.start();
                query_user(para).then((res) => {
                     this.begCode(res.code,res.message);
                    // this.total = res.data.totalCount;
                    if (res.code == 0) {
                        for (let i in res.data.list) {
                            data.push({
                                key: res.data.list[i].id,
                                label: res.data.list[i].name
                            });
                        }
                    } else {
                        this.$router.push({
                            path: '/login'
                        });
                    }
                    //NProgress.done();
                });
                return data;
            };
            return {
                value1:new Date(),
                 fileList: {
                    token: JSON.parse(localStorage.getItem('key'))
                },
                address_detail: null,
                delVisible:false,
                verifyCode:'',
                userId:'',
                auth: [{
                    name: "待授权",
                    value: 0
                },{
                    name: "查看",
                    value: 1
                },{
                    name: "控制",
                    value: 2
                }, {
                    name: "管理员",
                    value: 3
                },{
                    name: "拒绝",
                    value: 4
                }],
                form: {
                    expirationStatus:'',//是否会过期, 1永不过期，0会过期。
                    expirationTime:'',//过期时间
                    logo:'',
                    name: '',
                    remark: '',
                    site: '',
                    phone: '',
                    longitude: '',
                    latitude: '',
                    address: '',
                    companyUserId: '',
                    dataRestrict:[],
                },
                userlists: generateDatas(),
                defaultProps: {
                    children: 'children',
                    label: 'name',
                    isLeaf: 'checked'

                },
                roleList: '',
                filters: {
                    name: '',
                    phone:''
                },
                users: [],
                total: 0,
                page: 1,
                listLoading: false,
                sels: [], //列表选中列
                exentform: [],
                editexentble: false, //权限编辑页面是否显示
                editFormVisible: false, //编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    userName: [{
                        required: true,
                        message: '请输入用户名',
                        trigger: 'blur'
                    },{ min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }],
                    phone: [{
                        required: true,
                        message: '请输入手机号码',
                        trigger: 'blur'
                    },  {
                    // pattern: /^((1[3589][0-9])|(14[57])|(17[03678])|(19[7]))\d{8}$/,
                    pattern: /^((1[35689][0-9])|(14[56789])|(17[012345678])|(19[7]))\d{8}$/,
                    message: "请填写正确手机号码",
                    trigger: "blur"
                    }]
                },
                //编辑界面数据
                editForm: {
                    childUserId: 0,
                    userName: '',
                    remark: '',
                    address: '',
                    phone: '',
                    authType: ''

                },
                editrole: {
                    childUserId: '',
                    roleList: [],
                },
                addFormVisible: false, //新增界面是否显示
                addLoading: false,
                addFormRules: {
                    userName: [{
                        required: true,
                        message: '请输入用户名',
                        trigger: 'blur'
                    },{ min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }],
                    nickName: [{
                        required: true,
                        message: '请输入昵称',
                        trigger: 'blur'
                    },{ min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }],
                     phone: [{
                        required: true,
                        message: '请输入手机号码',
                        trigger: 'blur'
                    },  {
                    // pattern: /^((1[3589][0-9])|(14[57])|(17[03678])|(19[7]))\d{8}$/,
                    pattern: /^((1[35689][0-9])|(14[56789])|(17[012345678])|(19[7]))\d{8}$/,
                    message: "请填写正确手机号码",
                    trigger: "blur"
                    }],
                    companyName:[{
                        required: true,
                        message: '请输入组织名',
                        trigger: 'blur'
                    }],
                     password:[{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    }],
                    // email:[{
                    //     pattern: /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
                    //     message: "请输入正确的邮箱",
                    //     trigger: "blur"
                    // },]
                },
                //新增界面数据
                addForm: {
                    userName: '',
                    nickName: '',
                    phone: '',
                    password: "",
                    roleList: [],
                    companyName:"",
                    dataRestrict:[],
                    email: '',
                    // roleList: [],
                    // password: '',
                    // authType: '0'

                },
                companyVisible: false
            }
        },
        computed:{
            buttonColor(){
                return this.$store.state.buttonColor
            },
            titleColor(){
                return this.$store.state.titleColor
            },
            dialogTitleColor(){
                return this.$store.state.dialogTitleColor
            },
        },
        methods: {
            map() {
                var th = this;
                let self = this;
                let map = new BMap.Map(this.$refs.editmap);
                // 创建Map实例
                // map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);
                var poi = new BMap.Point(this.form.longitude, this.form.latitude);
                map.addControl(new BMap.NavigationControl());
                map.enableScrollWheelZoom(poi, 5);
                let pt1 = new BMap.Point(
                    this.form.longitude,
                    this.form.latitude
                );
                let marker1 = new BMap.Marker(pt1);
                map.addOverlay(marker1);
                map.centerAndZoom(poi, 15);
                var ac = new BMap.Autocomplete( //建立一个自动完成的对象
                    {
                        "input": "editId",
                        "location": map
                    })
                var myValue
                ac.addEventListener("onconfirm", function (e) { //鼠标点击下拉列表后的事件
                    var _value = e.item.value;
                    myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
                    self.address_detail = myValue;
                    self.form.address = myValue;
                    setPlace();
                });

                function setPlace() {
                    map.clearOverlays(); //清除地图上所有覆盖物
                    function myFun() {
                        th.userlocation = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
                        map.centerAndZoom(th.userlocation, 18);
                        map.addOverlay(new BMap.Marker(th.userlocation)); //添加标注

                        self.form.longitude = th.userlocation.lng;
                        self.form.latitude = th.userlocation.lat;
                        console.log(th.userlocation)
                    }
                    var local = new BMap.LocalSearch(map, { //智能搜索
                        onSearchComplete: myFun
                    });
                    local.search(myValue);

                    //测试输出坐标（指的是输入框最后确定地点的经纬度）
                    map.addEventListener("click", function (e) {
                        //经度
                        console.log(th.userlocation.lng);
                        //维度
                        console.log(th.userlocation.lat);

                    })
                }
                // map.addEventListener("mousemove", function (e) {
                //     console.log(e.point)
                // });
                map.addEventListener("click", function (e) {
                    map.clearOverlays()
                    //    alert(JSON.stringify(e.point))
                    let pt = new BMap.Point(
                        e.point.lng,
                        e.point.lat
                    );
                    self.form.longitude = e.point.lng;
                    self.form.latitude = e.point.lat;
                    let marker = new BMap.Marker(pt);
                    map.addOverlay(marker);
                    var geoc = new BMap.Geocoder();
                    let addComp, address;
                    geoc.getLocation(e.point, function (rs) {
                        addComp = rs.addressComponents;

                        self.form.province = addComp.province;
                        self.form.city = addComp.city;
                        self.form.county = addComp.district;
                        address = addComp.province + addComp.city + addComp.district + addComp.street +
                            addComp.streetNumber;

                        self.form.address = address;

                    });



                });
            },

            codeadd() {
                console.log(this.dellist)
          
                send_auth_pass_code().then((res) => {

                    this.begCode(res.code, res.message);
                    //NProgress.done();
                    if (res.code == 0) {
                        this.$message({
                            message: '发送成功,请耐心等待',
                            type: 'success'
                        });
                    }

                });
            },
            indexMethod(index) {
                let num = (this.page - 1) * 10 + index + 1;
                return num;
            },
            stateput(s) {
                let para = {
                    idList: [s.companyId]
                }
 
                if (s.status == 1) {
                    company_enable(para).then((res) => {

                         this.begCode(res.code,res.message);
                        if (res.code == 0) {

                            //NProgress.done();
                            this.$message({
                                message: '启用成功',
                                type: 'success'
                            });

                            this.getUsers();
                            console.log(s)
                        }
                    });
                } else {
                   company_disable(para).then((res) => {

                         this.begCode(res.code,res.message);
                        if (res.code == 0) {

                            //NProgress.done();
                            this.$message({
                                message: '停用成功',
                                type: 'success'
                            });

                            this.getUsers();

                        }
                    });
                }

            },
            reset_passwords(s) {
                this.$confirm('确认重置密码吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    //NProgress.start();
                    let para = {

                        childUserId: s,
                        
                        passWord: '888888'
                    };
                    user_reset_child_pass(para).then((res) => {

                         this.begCode(res.code,res.message);
                        if (res.code == 0) {

                            this.listLoading = false;
                            //NProgress.done();
                            this.$message({
                                message: '重置密码成功',
                                type: 'success'
                            });

                            this.editFormVisible = false;
                            this.getUsers();

                        }
                    });
                }).catch(() => {

                });
            },
            companySubmit() {
                let para = this.form;
                // this.form.attr1=JSON.stringify(this.auth);
                console.log(this.form)
                // return false;
                if (this.form.id) {

                    company_put(para).then((res) => {
                         this.begCode(res.code,res.message);
                        this.companyVisible = false;
                        this.getUsers();
                        this.$message({
                            message: '修改成功',
                            type: 'success'
                        });
                    });
                } else {
                    company_post(para).then((res) => {
                         this.begCode(res.code,res.message);
                        this.companyVisible = false;
                        this.getUsers();
                        this.$message({
                            message: '添加成功',
                            type: 'success'
                        });
                        //NProgress.done();
                    });
                }
            },
            formatSex: function (row, column) {
                return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
            },
            handleCurrentChange(val) {
                this.page = val;
                this.getUsers();
            },
            //获取组织列表
            getUsers() {

                let para = {
                    pageNo: this.page,
                    pageSize: 10,
                    name:'',
                    name: this.filters.name,
                    phone: this.filters.phone,
                };
                this.listLoading = true;
                //NProgress.start();
                user_querycompany(para).then((res) => {                  
                     this.begCode(res.code,res.message);
                    this.page = res.data.pageNo;
                    this.total = res.data.totalCount;
                    // console.log(res);
                    this.users = res.data.list;
                    for(let i in this.users){
                        if(!this.users[i].expirationTime){
                            this.users[i].expirationTime = '永不过期'
                        }    
                    }
                    this.listLoading = false;
                    //NProgress.done();
                    // console.log(this.users,"=====================================================")
                });
            },
            //删除
            delclick(){
                    //NProgress.start();
                    if(!this.verifyCode){
                        this.$message({
                                message: '请输入验证码',
                                type: 'warning'
                            });
                            return false;
                    }
                    let para = {
                        companyId: this.userId,
                        verifyCode:this.verifyCode
                    };
                    console.log(para)
                    user_delete_company(para).then((res) => {
                        this.begCode(res.code,res.message);
                        if (res.code == 0) {

                            this.delVisible = false;
                            this.verifyCode='';
                            //NProgress.done();
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });

                            this.getUsers();

                        }
                    });
            },
            handleDel: function (index, row) {
                this.userId=row.companyId;
                this.delVisible = true;
                console.log(row)
                return false;
                this.$confirm('确认删除该用户吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = {
                        companyId: row.companyId
                    };
                    user_delete_company(para).then((res) => {
                         this.begCode(res.code,res.message);
                        if (res.code == 0) {

                            this.listLoading = false;
                            //NProgress.done();
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });

                            this.getUsers();

                        }
                    });
                }).catch(() => {

                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                let para = {
                    childUserId: row.userId
                }
                user_get_childr(para).then((res) => {
                     this.begCode(res.code,res.message);
                    this.editrole.childUserId = row.userId;
                    console.log(res)

                    res.data.status = res.data.status.toString();
                    res.data.authType = res.data.authType.toString();
                    this.editFormVisible = true;
                    this.editForm = {
                        childUserId: res.data.userId,
                        email: res.data.email,
                        phone: res.data.phone,
                        remark: res.data.remark,
                        address: res.data.address,
                        userName: res.data.userName,
                        status: res.data.status,
                        authType: res.data.authType,
                    }
                })
            },
            getdata(date) {

				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				m = m < 10 ? ('0' + m) : m;
				var d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				var h = date.getHours();
				h = h < 10 ? ('0' + h) : h;
				var minute = date.getMinutes();
				minute = minute < 10 ? ('0' + minute) : minute;
				var second = date.getSeconds();
				second = second < 10 ? ('0' + second) : second;
				return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;

			},
            second2(){
                  this.form.expirationTime = ""
            },
            second1(){
                this.form.expirationTime = this.getdata(this.value1)
                console.log(this.form.expirationTime)
            },
            //上传照片
            handleAvatarSuccess(res, file) {
                console.log(file.type);
                this.form.logo = res.data.path;
                // this.form.devicePictureList[0].path = res.data.path;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isPNG = file.type === 'image/png';
                const isGIF = file.type === 'image/gif';
                let tp = false;
                if (isJPG) {
                    tp = isJPG;
                } else if (isPNG) {
                    tp = isPNG
                } else if (isGIF) {
                    tp = isGIF
                } else {

                }
                const isLt2M = file.size / 1024 / 1024 < 1;
                if (!isJPG && !isPNG && !isGIF) {
                    this.$message.error('上传头像图片只能是 JPG,GIF,PNG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 1MB!');
                }
                return tp && isLt2M;
            },
            companyedit(index, row) {
                this.companyVisible = true;
                let para1 = {
                    companyId: row.companyId
                }
                // console.log(row)
                company_get(para1).then((res) => {
                     this.begCode(res.code,res.message);
                    //    this.form=res
                    if (res.data) {
                        this.form = res.data;
                        // this.auth = JSON.parse(res.data.attr1);
                        console.log(res.data)
                    } else {
                        this.form = {
                            name: '',
                            remark: '',
                            site: '',
                            phone: '',
                            longitude: '',
                            latitude: '',
                            address: '',
                            companyUserId: row.userId,
                        }
                    }
                })
                 this.map();
            },
            exentEdit: function () {
                this.editrole.roleList=[];
                this.editexentble = true;
                let para1 = {
                    childUserId: this.form.id
                }
                user_role_query_child_user(para1).then((res) => {
                     this.begCode(res.code,res.message);
                    this.editrole.childUserId = this.form.id;
                    for (let i in res.data.list) {
                        this.editrole.roleList.push(res.data.list[i].id);
                    }
                    console.log(res)
                })
            },
            //显示新增界面
            handleAdd: function () {
                this.addFormVisible = true;
                this.addForm = {
                    userName: '',//账号
                    phone: '',//手机
                    password: "",//密码
                    companyName:"",//组织名
                    roleList: [],//权限
                    dataRestrict:[],//等级
                    // userName: '',
                    // phone: '',
                    // password: "",
                    email: '',
                    // roleList: [],
                    // password: '',
                    // authType: '0'
                };
            },
            //         renderContent(h, { node, data, store }) {
            //     return (
            //       <span class="custom-tree-node">
            //         <span>{node.label}</span>
            //         <span>
            //           <el-button size="mini" type="text" on-click={ () => this.append(data) }>Append</el-button>
            //           <el-button size="mini" type="text" on-click={ () => this.remove(node, data) }>Delete</el-button>
            //         </span>
            //       </span>);
            //   }
            //编辑
            editSubmitrole: function () {
                this.$confirm('确认提交吗？', '提示', {}).then(() => {
                    this.editLoading = true;
                    //NProgress.start();
                    let para = this.editrole;
                    console.log(para)
                    user_edit_child_role(para).then((res) => {
                         this.begCode(res.code,res.message);
                        if (res.code == 0) {
                            this.editLoading = false;
                            //NProgress.done();
                            this.$message({
                                message: '提交成功',
                                type: 'success'
                            });
                            this.$refs['editForm'].resetFields();

                            this.editexentble = false;
                            this.getUsers();

                        }
                    });
                });
            },
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = this.editForm;
                            user_edit_child(para).then((res) => {
                                 this.begCode(res.code,res.message);
                                 
                                    this.editLoading = false;
                                if (res.code == 0) {

                                    //NProgress.done();
                                    this.$message({
                                        message: '提交成功',
                                        type: 'success'
                                    });
                                    
                                    this.$refs['editForm'].resetFields();
                                    this.editFormVisible = false;
                                    this.getUsers();

                                }
                            });
                        });
                    }
                });
            },
            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        if(!this.addForm.userName){
                        this.$message({
                                    message: '请填写用户名',
                                    type: 'warning'
                                });
                                return false;
                        }
                        if(!this.addForm.phone){
                            this.$message({
                                        message: '请填写手机号码',
                                        type: 'warning'
                                    });
                                    return false;
                        }
                        if(!this.addForm.companyName){
                            this.$message({
                                        message: '请填写组织名称',
                                        type: 'warning'
                                    });
                                    return false;
                        }

                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            //NProgress.start();
                            for (var i in this.addForm.roleList) {
                                this.addForm.roleList[i] = parseInt(this.addForm.roleList[i]);
                            }
                            let para = Object.assign({}, this.addForm);
                            console.log(para)
                            user_add_childcompany(para).then((res) => { 
                                this.begCode(res.code, res.message);
                                if (res.code == 0) {
                                    this.$message({
                                        message: '提交成功',
                                        type: 'success'
                                    });
                                    this.$refs['addForm'].resetFields();
                                    this.addFormVisible = false;
                                    this.getUsers();
                                }
                                this.addLoading = false;
                                //NProgress.done();

                            });
                        });
                    }
                });
            },
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.id).toString();
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = {
                        ids: ids
                    };
                    batchRemoveUser(para).then((res) => {
                         this.begCode(res.code,res.message);
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getUsers();
                    });
                }).catch(() => { 

                });
            },
            //跳转到组织详情
            details(index,row){
                // console.log(index)
                // console.log(row)
                sessionStorage.setItem('company_detail',row.companyId)
                this.$router.push({
                    path: '/company/companyDetail'
                })
            },
            // 跳转到客户关系界面
            dendrogram(index,row){
                // console.log(row.companyId)
                sessionStorage.setItem('dendrogram_detail',row.companyId)
                this.$router.push({
                    path:'/company/companyTree'
                })
            }
        },
        
        mounted() {
            this.getUsers();
            let para = {
                pageNo: 1,
                pageSize: 1000
            };
            this.listLoading = true;
            //NProgress.start();
            query_user(para).then((res) => {
                 this.begCode(res.code,res.message);
                // this.total = res.data.total;
                // console.log(res);
                this.roleList = res.data.list;
                this.listLoading = false;
                // console.log(this.roleList,"=========================")
                //NProgress.done();
            });
        }
    }
</script>

<style>
    #editmap{
        height: 300px;
    }
    .tangram-suggestion-main {
        z-index: 9999999999;
    }
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>